<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="my" uri="http://amani.com/function-taglib"%>
<!DOCTYPE html >
<html>
<head>
	<title>阿玛尼</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta name="format-detection" content="telephone=no">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<link rel="stylesheet" type="text/css" media="screen" href="${ROOT_PATH }content/scripts/bootstrap/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" media="screen" href="${ROOT_PATH }content/css/storefront.css">
	<script src="${ROOT_PATH }content/scripts/jquery-1.10.1.min.js"></script>
	<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
	<style type="text/css">
		*{color:#ff000}
		li{font-size:20px;float:left ;width:45%;list-style-type:none;}
	</style>
</head>
<body>
	<section>
		<c:forEach var="card" items="${ActivateCard }">
			<ul>
				<li class="font-y">${card.code }</li>
				<li class=""><button data-code="${card.code }">领取</button></li>
			</ul>
		</c:forEach>
	</section>
	<script type="text/javascript">
		$(function () {
			wx.config({
				debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
				appId: '${appId}', // 必填，公众号的唯一标识
				timestamp:"${jsapi_timestamp}", // 必填，生成签名的时间戳
				nonceStr: '${jsapi_nonceStr}', // 必填，生成签名的随机串
				signature: '${jsapi_signature}', // 必填，签名，见附录1
				jsApiList: ['addCard', 'hideOptionMenu','closeWindow'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
			});
			wx.ready(function () {
				wx.hideOptionMenu();
				$("button").click(function(){
					var code = $(this).attr("data-code");
					$.ajax({
						 type: "post",
				         url: "${ROOT_PATH}UCenter/sendCard/send",
				         data: {"electronicCardNo":code},
				         dataType: "json",
				         success: function (o) { 
							var cardInfo={cardId: o.cardId, cardExt: JSON.stringify(o.cardExt)};
				        	var addCardInfo={cardList:[],success: function (res) {
		                           if (res.cardList) {
		                               alert('添加卡包成功');
		                           } else{
		                               altTip('添加卡包失败');
		                           }
		                           wx.closeWindow();
		                       }};
				        	addCardInfo.cardList.push(cardInfo);
			                wx.addCard(addCardInfo); 
				         }
					});
				})
			});
		});
	</script>
</body>
</html>